package com.ctz.commonframe.ui.widget;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class AbsAdapter<T> extends BaseAdapter {
	protected Context context;
	protected List<T> datas;
	protected LayoutInflater inflater;
	protected int layoutId;

	public AbsAdapter(Context context, List<T> datas, int layoutId) {
		this.context = context;
		inflater = LayoutInflater.from(context);
		this.datas = datas;
		this.layoutId = layoutId;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public T getItem(int position) {
		return position > datas.size() - 1 || position < 0 ? null : datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AdapterViewHolder holder = AdapterViewHolder.getInstance(context, convertView, parent, layoutId, position);
		convert(holder, getItem(position));
		return holder.getConvertView();
	}

	public abstract void convert(AdapterViewHolder holder, T data);

}
